//
//  DTUIInput.m
//  PersonalManager
//
//  Created by user on 16/8/12.
//  Copyright © 2016年 Haiyun.Qian. All rights reserved.
//

#import "DTUIInput.h"

@interface DTUIInput()<UITextFieldDelegate>

@property (nonatomic, strong) UITextField *textField;

@end

@implementation DTUIInput
-(instancetype)init {
    self = [super init];
    
    self.textField = [[UITextField alloc]init];

    return self;
}

-(void) initTextField {
    _textField.frame = CGRectMake(80, CGRectGetHeight(_command.controller.view.bounds)/2 - 60, CGRectGetWidth(_command.controller.view.bounds) - 160,40);
    _textField.borderStyle = UITextBorderStyleRoundedRect;
    _textField.layer.cornerRadius = 15;
    _textField.delegate = self;
    _textField.placeholder = @"aaaaaaa";
    [_textField becomeFirstResponder];
//    _textField.backgroundColor = [UIColor lightGrayColor];
    [_command.controller.view addSubview:_textField];

}
-(void)plain:(DTJavascriptCommand *)command {
    self.command = command;
    [self initTextField];
}

-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    
    return true;
}
-(BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:_textField.text,@"plain输入内容：", nil];
    [_command successRessponse:dic];
    
    [_textField resignFirstResponder];
    _textField.text = nil;
    [self.textField removeFromSuperview];
    
    return true;
}
//-(void)textFieldDidEndEditing:(UITextField *)textField {
//    [self.textField removeFromSuperview];
//}

@end
